jQuery(document).ready(function($) {
   $("#lostPassForm").jobUtil("setCaptcha", {
      captchaurl: showcaptchaurl
   });

   $("#lostPassForm").validate({
      messages: {
         checkemail: {
            email: "请输入正确格式的电子邮件"
         },
      }, 
      failure: function(label) {
        label.removeClass("checked");
      },
      success: function(label) {
         if(label.attr("for") == "captcha_code")
            return; 
         // set &nbsp; as text for IE
         label.addClass("checked");
      },

      submitHandler: function(form) {
         $(form).ajaxSubmit({
           dataType: "json", 
           beforeSubmit: function(data, form, options) { 
               if(!showLoading(form))
                  return false;
               $("#regmsg", form).hide(); 
            },
            success: function(data, statusText, xhr, form) {
              try {
                 var retmsg = data; 
                 if(retmsg.error) { 
                     $("#regmsg", form).jobUtil("showError", retmsg.error); 
                      if(!/captcha_code/.test(retmsg.error))
                         $("#captcha_reload", form).trigger("click");
                 }
                 else if(retmsg.success) {
                     var html = "<div class='medium note'><span id='success_wait'>10</span>秒钟后，网页自动进入登录页面……</div>";
                     html = "<div class='successmsg lostPassMsg'>" + 
                            "<div class='head'><img src='/images/3/submit_success.png'/><div class='text'>" + 
                            retmsg.success + html + 
                            "</div></div>" +  
                            "<div class='actions'>" + "<a href='"+loginurl+"'>返回登录页</a>" + "</div>" + 
                            "</div>";
                     
                     $("#t1", form).fadeOut(function() {
                        $(this).after(html); 
                        $("#success_wait", form).jobUtil("timerDown", function() {
                           window.location = loginurl; 
                        }); 
                     });
                 }
                     
              } catch(e) {
                 return false;
              }
            }
        });
      }

  });

   $("#lostPassForm #checkemail").jobUtil("emailProvider");
   // focus first text-field 
   setFocus("lostPassForm");

}); 
